<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\business\BusinessVariety;
use common\components\Upload;
use yii\web\JsExpression;
/* @var $this yii\web\View */
/* @var $model common\models\business\BusinessPigFile */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="row">
    <div class="col-lg-12">
        <section class="panel">
        <div class="panel-body">
            <div class="adv-table editable-table ">
                <div class="business-pig-file-form">
                    <?php $form = ActiveForm::begin([
                        'options' => ['class' => 'form-horizontal','enctype' => 'multipart/form-data'],
                        'fieldConfig' => [
                            'template' => "<div class='col-xs-3 col-sm-2 text-right'>{label}</div><div class='col-xs-9 col-sm-7'>{input}</div><div class='col-xs-12 col-xs-offset-3 col-sm-3 col-sm-offset-0'>{error}</div>",
                        ]
                    ]); ?>
                        <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

                        <?= $form->field($model, 'no')->textInput(['maxlength' => true]) ?>

                        <?= $form->field($model, 'father')->textInput(['maxlength' => true]) ?>

                        <?= $form->field($model, 'mathor')->textInput(['maxlength' => true]) ?>

                        <?= $form->field($model, 'variety')->dropDownList(\yii\helpers\ArrayHelper::map(BusinessVariety::find()->asArray()->all(),'id','title')) ?>

                        <?= $form->field($model, 'constract_id')->widget(\kartik\select2\Select2::className(), [
                            'options' => ['placeholder' => '请输入合同名称...'],
                            'initValueText'=>!$model->constract?'':$model->constract->name,
                            'pluginOptions' => [
                                'allowClear' => true,
                                'minimumInputLength' => 1,//重要
                                'language' => [
                                    'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                                ],
                                'ajax' => [
                                    'url' => '/business/search/search-contract',
                                    'dataType' => 'json',
                                    'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                                    'cache' => true
                                ],
                                'width' => '400px',
                                'escapeMarkup' => new JsExpression('function (markup) { return markup;}'),
                                'templateResult' => new JsExpression('function(res) { return res.text;}'),
                                'templateSelection' => new JsExpression('function (res) { return res.text;}'),
                            ],
                        ]);
                        ?>



                        <?= $form->field($model, 'pigs')->widget(\kartik\select2\Select2::className(), [
                            'data' =>$ids,
                            'pluginOptions' => [
                                'tags' => true,
                                'allowClear' => true,
                                'language' => [
                                    'errorLoading' => new JsExpression("function () { return 'Waiting...'; }"),
                                ],
                                'ajax' => [
                                    'url' => '/business/search/search-pig',
                                    'dataType' => 'json',
                                    'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                                    'cache' => true
                                ],
                                'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                                'templateResult' => new JsExpression('function(res) { return res.text; }'),
                                'templateSelection' => new JsExpression('function (res) { return res.text; }'),
                                'maximumInputLength' => 10
                            ],
                            'options' => ['placeholder' => '输入对应的仔猪编号', 'multiple' => true],
                        ]);
                        ?>

                        <?php
                            echo $form->field($model, 'matherphoto')->widget(\kartik\widgets\FileInput::classname(), [
                                'attribute' => 'matherphoto',
                                'options' => ['multiple' => false],
                                'pluginOptions' => [
                                    // 需要预览的文件格式
                                    'previewFileType' => 'image',
                                    // 预览的文件
                                    'initialPreview' => Upload::checkGetUrl($model->matherphoto)?Upload::checkGetUrl($model->matherphoto):'',
                                    // 需要展示的图片设置，比如图片的宽度等
                                    'initialPreviewConfig' => \common\components\Upload::initialPreviewConfig($model,'matherphoto',\common\models\business\BusinessPigFile::tableName(),$model->id),
                                    // 是否展示预览图
                                    'initialPreviewAsData' =>  true,
                                    'maxFileCount' => 1,
                                    // 是否显示移除按钮，指input上面的移除按钮，非具体图片上的移除按钮
                                    'showRemove' => true,
                                    // 是否显示上传按钮，指input上面的上传按钮，非具体图片上的上传按钮
                                    'showUpload' => false,
                                    //是否显示[选择]按钮,指input上面的[选择]按钮,非具体图片上的上传按钮
                                    'showBrowse' => true,
                                    // 展示图片区域是否可点击选择多文件
                                    // 'browseOnZoneClick' => true,
                                    // 如果要设置具体图片上的移除、上传和展示按钮，需要设置该选项
                                    'fileActionSettings' => [
                                        // 设置具体图片的查看属性为false,默认为true
                                        'showZoom' => true,
                                        // 设置具体图片的上传属性为true,默认为true
                                        'showUpload' => true,
                                        // 设置具体图片的移除属性为true,默认为true
                                        'showRemove' => true,
                                    ],
                                ],
                            ]);
                        ?>

                        <?php
                        echo $form->field($model, 'fatherphoto')->widget(\kartik\widgets\FileInput::classname(), [
                            'attribute' => 'fatherphoto',
                            'options' => ['multiple' => false],
                            'pluginOptions' => [
                                // 需要预览的文件格式
                                'previewFileType' => 'image',
                                // 预览的文件
                                'initialPreview' => Upload::checkGetUrl($model->fatherphoto)?Upload::checkGetUrl($model->fatherphoto):'',
                                // 需要展示的图片设置，比如图片的宽度等
                                'initialPreviewConfig' => \common\components\Upload::initialPreviewConfig($model,'fatherphoto',\common\models\business\BusinessPigFile::tableName(),$model->id),
                                // 是否展示预览图
                                'initialPreviewAsData' =>  true,
                                'maxFileCount' => 1,
                                // 是否显示移除按钮，指input上面的移除按钮，非具体图片上的移除按钮
                                'showRemove' => true,
                                // 是否显示上传按钮，指input上面的上传按钮，非具体图片上的上传按钮
                                'showUpload' => false,
                                //是否显示[选择]按钮,指input上面的[选择]按钮,非具体图片上的上传按钮
                                'showBrowse' => true,
                                // 展示图片区域是否可点击选择多文件
                                // 'browseOnZoneClick' => true,
                                // 如果要设置具体图片上的移除、上传和展示按钮，需要设置该选项
                                'fileActionSettings' => [
                                    // 设置具体图片的查看属性为false,默认为true
                                    'showZoom' => true,
                                    // 设置具体图片的上传属性为true,默认为true
                                    'showUpload' => true,
                                    // 设置具体图片的移除属性为true,默认为true
                                    'showRemove' => true,
                                ],
                            ],
                        ]);
                        ?>



                    <div class="form-group">
                        <?= Html::submitButton($model->isNewRecord ? '确认提交' : '确认更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
                    </div>
                    <?php ActiveForm::end(); ?>
                </div>
            </div>
        </div>
    </section>
</div>
</div>